﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace HPPUtil
{
    public static class StaticHelper
    {
        /// <summary>
        /// 获取类的Property的名字字符串
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="propertySelector"></param>
        /// <returns></returns>
        public static string GetPropertyName<T>(Expression<Func<T, ValueType>> propertySelector)
        {
            var memberExpression = propertySelector.Body as MemberExpression;
            if (memberExpression != null)
            {
                return memberExpression.Member.Name;
            }
            else
            {
                return string.Empty;
            }
        }

        /// <summary>
        /// 获取类的Property的名字字符串
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="propertySelector"></param>
        /// <returns></returns>
        public static string GetPropertyName<T>(Expression<Func<T, object>> propertySelector)
        {
            var memberExpression = propertySelector.Body as MemberExpression;
            if (memberExpression != null)
            {
                return memberExpression.Member.Name;
            }
            else
            {
                return string.Empty;
            }
        }
    }
}
